//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Resource Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;

namespace EntLibContrib.Resource.Configuration.Design
{
	/// <summary>
	/// Represents a command for adding the Resource Application Block to the current application.
	/// </summary>
	public class AddResourceManagerSettingsNodeCommand : AddChildNodeCommand
	{
		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="AddResourceManagerSettingsNodeCommand"/> class with an <see cref="IServiceProvider"/>.
		/// </summary>
		/// <param name="serviceProvider">A mechanism for retrieving a service object; that is, an object that provides custom support to other objects.</param>
		public AddResourceManagerSettingsNodeCommand (IServiceProvider serviceProvider)
			: base(serviceProvider, typeof(ResourceManagerSettingsNode))
		{
		}
		#endregion

		#region Protected Methods
		/// <summary>
		/// <para>Adds the <see cref="ResourceManagerSettingsNode"/> to the current application with a default <see cref="ResourceManagerNode"/>.</para>
		/// </summary>
		/// <param name="e"><para>An <see cref="EventArgs"/> containing the event data.</para></param>
		protected override void OnExecuted (EventArgs e)
		{
			base.OnExecuted(e);
			ResourceManagerSettingsNode node = ChildNode as ResourceManagerSettingsNode;

			ResourceManagerCollectionNode resourceManagerCollectionNode = new ResourceManagerCollectionNode();
			node.AddNode(resourceManagerCollectionNode);
			int defaultNodeIdx = resourceManagerCollectionNode.AddNode(new ResourceManagerNode());
			node.DefaultResourceManager = (ResourceManagerNode)resourceManagerCollectionNode.Nodes[defaultNodeIdx];
		}
		#endregion
	}
}